<%@page import="com.sq.partner.manager.mybatis.model.TradProdInst"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>产品编辑</title>

<style type="text/css">
input.fieldError {
border: 1px solid #ffb042;
background-color: #fffbf5;
}
textarea.fieldError {
border: 1px solid #ffb042;
background-color: #fffbf5;
}
label.fieldError {
line-height: 23px;
color: #ffb042;
padding-left: 6px;
}
</style>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script type="text/javascript">
var startP=1;
var tradProdCode=${product.tradProdCode};


var Formstatus=true;
$(document).ready(function() {
	
	loadProdTypes(); //加载“产品类型”下拉列表
	loadPoolTypes(); //加载“共保选项” 下拉列表
	
	loadDiscountType();//加载"折扣系数"下拉列表
	loadInsurePeriod();//加载"保险期间"下拉列表
	var $inputForm = $("#inputForm");
	
	var $prodInstCode = $("#prodInstCode");
    var $maxDays = $("#maxDays");
	var $minDays = $("#minDays");
	var $unitPp = $("#unitPp");
	var $tradAppType = $("#tradAppType");
	var $instant = $("#instant");
	var $maxDelayDay = $("#maxDelayDay");
	var $minDelayDay = $("#minDelayDay");
	var $tradProdDesc = $("#tradProdDesc");
	var $status = $("#status");
	//加载时 给select 选中状态
	$("#tradAppType").find("option[value='${product.tradAppType}']").attr("selected",true);
	$("#tradAppType").attr("disabled","disabled"); 
	$("#status").find("option[value='${product.status}']").attr("selected",true);  
	$("#instant").find("option[value='${product.instant}']").attr("selected",true);
	$('#ageLimit').find("option[value='${product.ageLimit}']").attr("selected",true);
	checkLimit();
	
	$('#maxOccupLevel').find("option[value='${product.maxOccupLevel}']").attr("selected",true);
	$('#insuredNoLimit').find("option[value='${product.insuredNoLimit}']").attr("selected",true);
	$('#agentType').find("option[value='${product.agentType}']").attr("selected",true);
	$("#agentType").attr("disabled","disabled"); 
	checkInsuredNoLimit();

	//最短延时起保天数：不小于0的整数，且首位非0
	$minDelayDay.change(function(){
		if($minDelayDay.val()!=""){
			var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
			var delayflag = minDelayDayReg.test($minDelayDay.val());
			if(!delayflag) $.message("error","最短延时起保天数必须是不小于0的整数");
		}
	});

	//最长延时起保天数：不小于0的整数，且首位非0
	$maxDelayDay.change(function(){
		if($maxDelayDay.val()!=""){
			var maxDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
			var delayflag = maxDelayDayReg.test($maxDelayDay.val());
			if(!delayflag){
				 $.message("error","最长延时起保天数必须是不小于0的整数");
				 return;
			}
			if(parseInt($minDelayDay.val())>parseInt($maxDelayDay.val())){
				$.message("error","最长延时起保天数不能小于延时起保天数");
				return;
			}
		}
	});;
	
	//最短保险天数：大于等于1的正整数
	$minDays.change(function(){
		if($minDays.val()!=""){
			var minDayReg = new RegExp("^[1-9][0-9]*$");
			var minDayflag = minDayReg.test($minDays.val());
			if(!minDayflag) $.message("error","最短保险天数必须是不小于1的整数");
		}
	});

	//最长保险天数：大于等于1的正整数，且必须大于最短保险天数
	$maxDays.change(function(){
		if($maxDays.val()!=""){
			var maxDayReg = new RegExp("^[1-9][0-9]*$");
			var maxDayflag = maxDayReg.test($maxDays.val());
			if(!maxDayflag) $.message("error","最长保险天数必须是不小于1的整数");
			if(parseInt($minDays.val())>parseInt($maxDays.val())){
				$.message("error","最长保险天数不能小于最短保险天数");
			}
		}
	});
	
	
	//共保份额
	var $poolRatio = $("#poolRatio");
	$poolRatio.change(function(){
		var regRatio = new RegExp("^([1-9][0-9]?|100)$");
	    if(!regRatio.test($poolRatio.val())){
	    	$.message("error","请输入0-100的有效整数");
	    	return;
	    }
	});
	//最大份数：不小于0的整数，且首位非0
	$unitPp.change(function(){
		if($unitPp.val()!=""){
			var unitPpReg = new RegExp("^(0|[1-9][0-9]*)$");
			var ppflag = unitPpReg.test($unitPp.val());
			if(!ppflag) $.message("error","最大份数必须是不小于0的整数");
		}
	});
	
});


//查询产品类型
function loadProdTypes(){
	$.ajax({
		url : "product/queryProdType",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{parentCode:1},//此为人险产品参数
		success:function(prodTypeList){
			if($.validate(prodTypeList))return;
			
			if(prodTypeList[0]!=undefined){		
				 $.each(prodTypeList,function(i,item){
					$("#prodType").append("<option value="+item.code+">"+item.codeName+"</option>");
				 });
				
				 $("#prodType").find("option[value='${product.tradProdType}']").attr("selected",true);
				 $("#prodType").attr("disabled","disabled"); 
			}
		}
	});
}


//查询共保选项
function loadPoolTypes(){
	$.ajax({
		url : "product/queryPoolType",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(poolTypeList){
			if($.validate(poolTypeList))return;
			
			if(poolTypeList[0]!=undefined){		
				 $.each(poolTypeList,function(i,item){
					$("#poolType").append("<option value="+item.code+">"+item.codeName+"</option>");
				 });
				 
				 $("#poolType").find("option[value='${product.poolType}']").attr("selected",true);
				 
				 var type = ${product.poolType};
				 <%
				 	Object obj = request.getAttribute("product");
				 	if(null!=obj){
				 		TradProdInst prod = (TradProdInst)obj;
				 		if(null!=prod.getPoolRatio()){
				 %>
					 var ratio = ${product.poolRatio};
					 if(type==1){
						 $('#poolRatio').attr('readonly',false);
						 $('#poolRatio').css("background-color",'white');
						 $('#poolRatio').val(Number(ratio)*100);
					 }
				 <%			
				 		}
				 	}
				 %>
			}
		}
	});
}

//查询保险期间
function loadInsurePeriod(){
	$.ajax({
		url : "product/queryInsurePeriod",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(insurePeriodList){
			if($.validate(insurePeriodList))return;
			
			if(insurePeriodList[0]!=undefined){		
				 $.each(insurePeriodList,function(i,item){
					$("#PPP_UNIT").append("<option value="+item.code+">"+item.codeName+"</option>");
				 });
				 $("#PPP_UNIT").find("option[value='${product.pppUnit}']").attr("selected",true);
			}
		}
	});
}
/*-----------------------------2015年6月5日10:07:57-----wangyan------add↓---*/
//获取折扣系数选项
function loadDiscountType(){
	$.ajax({
		url : "product/getDiscountType",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(discountTypeList){
			if($.validate(discountTypeList))return;
			if(null!=discountTypeList && discountTypeList[0]!=undefined){	
				 $.each(discountTypeList,function(i,item){
					$("#adjust").append("<option value="+item.ADJUSTID+">"+item.ADJUSTDESC+"</option>");
				 });
				 if('${product.adjustStr}'!=""){
					 var obj= $.parseJSON('${product.adjustStr}')
					 if(obj.adjustId!=undefined){
						 $("#adjust").find("option[value="+obj.adjustId+"]").attr("selected",true);
					 }
					 if(obj.adjustList!=undefined){
						 for(var i=1;i<obj.adjustList.length;i++){
							 addAdjustDiv();
						 }
						 $("#adjustDiv").find("div").each(function(i){
							$(this).find("input[type='text']").each(function(){
								if($(this).attr("name")=="peoplenum"){
									$(this).val(obj.adjustList[i].cond1);
								}
								if($(this).attr("name")=="coefficient"){
									$(this).val(obj.adjustList[i].premRate*100);
								} 
							});
					    });
					 }
				 }else{
					 $("#adjustDiv").find("input[type='text']").each(function(){
						$(this).attr('readOnly',true);
						$(this).css('background-color','#ccc');
				     });
				 }
			}
		}
	});
}
function addAdjustDiv(){
	var adjustVal = $("#adjust").val()
	if(adjustVal!=""){
		$("#adjustDiv").append("<div>"+
				"<input name='peoplenum' type='text' style='width:55px;' class='input_text'>&nbsp;人&nbsp;<input name='coefficient' type='text'  style='width:55px;' class='input_text'>&nbsp;%&nbsp;&nbsp;<input type='button'  value='-' onclick='removeAdjustDiv(this)'>"
	    		+"</div>");
	}
}
function removeAdjustDiv(o){
	$(o).parent().remove()
}
/*-----------------2015年6月5日10:07:57------wangyan-----add↑-----*/


//表单校验
function checkFormFormate(){
	var $prodInstCode = $("#prodInstCode");
	var $prodInstName = $("#prodNme");
	var $tradProdDesc = $("#tradProdDesc");
	var $tradAppType = $("#tradAppType");
	var $prodType = $("#prodType");
	var $unitPp = $("#unitPp");
	var $maxDelayDay = $("#maxDelayDay");
	var $minDelayDay = $("#minDelayDay");
	var $instant = $("#instant");
	var $minDays = $("#minDays");
    var $maxDays = $("#maxDays");
    var $pppUnit = $("#PPP_UNIT");
    var $limit = $("#ageLimit");
    var $minAge = $("#minAge");
    var $maxAge = $("#maxAge");
    var $maxOccupLevel=$("#maxOccupLevel");
	var $insuredNoLimit=$("#insuredNoLimit");
	var $minInsuredNo= $("#minInsuredNo");
	
    if($.trim($prodInstCode.val()).length==0){
    	$.message("error","请选择产品模板");
    	$prodInstCode.focus();
    	return false;
    }
    //产品模板名称
    if($.trim($prodInstName.val()).length==0){
    	$.message("error","产品模板名称不能为空");
    	$prodInstName.focus();
    	return false;
    }
    //交易系统投保类型
    $tradAppType.val('${product.tradAppType}'); 
    if($.trim($tradAppType.val()).length==0){
    	$.message("error","个团标示不能为空");
    	$tradAppType.focus();
    	return false;
    }
    //产品类型
    $prodType.val('${product.tradProdType}');
    if($prodType.val()==0){
    	$.message("error","请选择界面投保流程");
    	$prodType.focus();
    	return false;
    }
 	//最短延时起保天数：不小于0的整数，且首位非0
    if($.trim($minDelayDay.val()).length==0){
    	$.message("error","请输入最短延时起保天数");
    	$minDelayDay.focus();
    	return false;
    }else{
    	var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
		var delayflag = minDelayDayReg.test($minDelayDay.val());
		if(!delayflag){
			$.message("error","最短延时起保天数必须是不小于0的整数");
			$minDelayDay.focus();
			return false;
		}
	}
    //最长延时起保天数：不小于0的整数，且首位非0
    if($.trim($maxDelayDay.val()).length==0){
    	$.message("error","请输入最长延时起保天数");
    	$maxDelayDay.focus();
    	return false;
    }else{
    	var maxDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
		var delayflag = maxDelayDayReg.test($maxDelayDay.val());
		if(!delayflag){
			$.message("error","最长延时起保天数必须是不小于0的整数");
			$maxDelayDay.focus();
			return false;
		}
		if(parseInt($minDelayDay.val())>parseInt($maxDelayDay.val())){
			$.message("error","最长延时起保天数不能小于最短延时起保天数");
			$maxDelayDay.focus();
			return false;
		}
	}
	//最小保险期间：大于等于1的正整数
    if($.trim($minDays.val()).length==0){
    	$.message("error","请输入最小保险期间");
    	$minDays.focus();
    	return false;
    }else{
		var minDayReg = new RegExp("^[1-9][0-9]*$");
		var minDayflag = minDayReg.test($minDays.val());
		if(!minDayflag){
			$.message("error","最小保险期间必须是不小于1的整数");
			$minDays.focus();
			return false;
		}
	}
	//最大保险期间：大于等于1的正整数，且必须大于最小保险期间
    if($.trim($maxDays.val()).length==0){
    	$.message("error","请输入最大保险期间");
    	$maxDays.focus();
    	return false;
    }else{
		var maxDayReg = new RegExp("^[1-9][0-9]*$");
		var maxDayflag = maxDayReg.test($maxDays.val());
			if(!maxDayflag){
			if($maxDays.val()!=0){
				$.message("error","最大保险期间必须是不小于1的整数");
				$maxDays.focus();
				return false;
			}
		}
		if(parseInt($minDays.val())>parseInt($maxDays.val())){
			$.message("error","最大保险期间不能小于最小保险期间");
			$maxDays.focus();
			return false;
		}
	}
  	//销售类型校验  2015年7月15日09:09:58
    var $agentType= $("#agentType");
    $agentType.val('${product.agentType}');
    if($agentType.val()==""){
    	$.message("error","请选择销售类型");
    	$agentType.focus();
    	return false;
    }
	//如果“共保选项”是“保单级共保”，则必须输入“共保份额”
    var $poolType = $.trim($("#poolType").val());
    var $poolRatio = $.trim($("#poolRatio").val());
    if($poolType==1){
    	if($poolRatio.length==0){
	    	$.message("error","请输入共保份额");
	    	$("#poolRatio").focus();
	    	return false;
    	}

    	//校验共保份额
	    var regRatio = new RegExp("^([1-9][0-9]?|100)$");
	    if(!regRatio.test($poolRatio)){
	    	$.message("error","请输入0-100的有效整数");
	    	$("#poolRatio").focus();
	    	return false;
	    }
    }
	//即时投保限制
    if($.trim($instant.val()).length==0){
    	$.message("error","即时投保限制不能为空");
    	$instant.focus();
    	return false;
    }
	//是否限制投保年龄
    if($limit.val()==""){
    	$.message("error","请选择投保年龄限制");
    	$limit.focus();
    	return false;
    }else{
    	var minageVal = $.trim($minAge.val());
    	var maxageVal = $.trim($maxAge.val());
    	if($limit.val()=="Y"){
    		if(minageVal==""){
    	    	$.message("error","请输入最低年龄");
    	    	$minAge.focus();
    	    	return false;
    		}else{
    			var regMinAge = /^([1-9]\d{0,2}|0)$/;
    			if(!regMinAge.test(minageVal)){
	    	    	$.message("error","请输入0-999的整数");
	    	    	$minAge.focus();
	    	    	return false;
    			}
    		}
    		if($.trim($maxAge.val())==""){
    	    	$.message("error","请输入最高年龄");
    	    	$maxAge.focus();
    	    	return false;
    		}else{
    			var regMaxAge = /^([1-9]\d{0,2}|0)$/;
    			if(!regMaxAge.test(maxageVal)){
	    	    	$.message("error","请输入0-999的整数");
	    	    	$maxAge.focus();
	    	    	return false;
    			}
    		}
    		
    		if(Number(minageVal)>Number(maxageVal)){
    			$.message("error","最低年龄不能大于最高年龄");
    			return false;
    		}
    	}
    }

  	//是否限制最低投保人数
    if($insuredNoLimit.val()==""){
    	$.message("error","请选择最低投保人数限制");
    	$insuredNoLimit.focus();
    	return false;
    }else{
    	var minInsuredNo = $.trim($minInsuredNo.val());
    	if($insuredNoLimit.val()=="Y"){
    		if(minInsuredNo==""){
    	    	$.message("error","请输入最低投保人数");
    	    	$minInsuredNo.focus();
    	    	return false;
    		}else{
    			var regMinAge = /^([1-9]\d{0,2}|0)$/;
    			if(!regMinAge.test(minInsuredNo)){
	    	    	$.message("error","请输入0-999的整数");
	    	    	$minAge.focus();
	    	    	return false;
    			}
    		}
    	}
    }
  	//最大份数：不小于0的整数，且首位非0
    if($.trim($unitPp.val()).length==0){
    	$.message("error","请输入最大份数");
    	$unitPp.focus();
    	return false;
    }else{
		var unitPpReg = new RegExp("^(0|[1-9][0-9]*)$");
		var ppflag = unitPpReg.test($unitPp.val());
		if(!ppflag){
			$.message("error","最大份数必须是不小于0的整数");
			$unitPp.focus();
			return false;
		}
	}
    /*-----------------2015年6月3日17:27:07-----wangyan------add↓---*/
    //折扣系数校验2015年6月3日17:27:07
    if("0001"==$("#adjust").val()){
    	if(!chectAdjust()){
         	return false;
         }
    }
    /*-----------------2015年7月15日10:33:58------wangyan-----add↑-----*/
	//产品描述
    if($.trim($tradProdDesc.val()).length==0){
    	$.message("error","交易系统产品描述不能为空");
    	$tradProdDesc.focus();
    	return false;
    }
	return true;
}

//添加产品
function addProduct(){
	if(!checkFormFormate())return;
	var $prodInstCode = $("#prodInstCode");
	var $prodInstName = $("#prodNme");
	var $tradProdDesc = $("#tradProdDesc");
	var $tradAppType = $("#tradAppType");
	var $unitPp = $("#unitPp");
	var $maxDelayDay = $("#maxDelayDay");
	var $minDelayDay = $("#minDelayDay");
	var $instant = $("#instant");
	var $minDays = $("#minDays");
    var $maxDays = $("#maxDays");
	var $PPP_UNIT = $("#PPP_UNIT");
    var $status = $("#status");
    var $prodType = $("#prodType");
    var $poolType = $("#poolType");
    var $poolRatio = $("#poolRatio");
    var $limit = $("#ageLimit");
    var $minAge = $("#minAge");
    var $maxAge = $("#maxAge");
    
    var $maxOccupLevel=$("#maxOccupLevel");
	var $insuredNoLimit=$("#insuredNoLimit");
	var $minInsuredNo= $("#minInsuredNo");
	var $agentType= $("#agentType");
    
	var tradProdDesc_val=$tradProdDesc.val();
	var tradAppType_val=$tradAppType.val();
	var prodInstCode_val=$prodInstCode.val();
	var instant_val=$instant.val();
	var maxDelayDay_val=$maxDelayDay.val();
	var minDelayDay_val=$minDelayDay.val();
	var minDays_val=$minDays.val();
	var maxDays_val=$maxDays.val();
	var PPP_UNIT_val=$PPP_UNIT.val();
	var unitPp_val=$unitPp.val();
	var status_val=$status.val();
	var prodType_val=$prodType.val();
    var poolType_val = $poolType.val();
    var poolRatio_val = $poolRatio.val();
    
	var limit_val=$limit.val();
    var minage_val = $minAge.val();
    var maxage_val = $maxAge.val();
    
    var maxOccupLevel_val=$maxOccupLevel.val();
	var insuredNoLimit_val=$insuredNoLimit.val();
	var minInsuredNo_val= $minInsuredNo.val();
	var agentType_val= $agentType.val();
	
	
	/*-----------------2015年6月5日10:42:18-----wangyan------add↓---*/
	var adjustObj = new Object();
	adjustObj.adjustId =$("#adjust").val();
	var adjustLis = [];
	
	$("#adjustDiv").find("div").each(function(){
		var adjust = new Object();
		$(this).find("input[type='text']").each(function(){
			if($(this).attr("name")=="peoplenum"){
				adjust.peoplenum=$(this).val();
			}
			if($(this).attr("name")=="coefficient"){
				adjust.coefficient=$(this).val();
			} 
		});
		adjustLis.push(adjust);
    });
	adjustObj.adjustList= adjustLis;
	var adjustStr_val = JSON.stringify(adjustObj);
	/*-----------------2015年6月5日10:42:18------wangyan-----add↑-----*/
	
	saveTradProInst({tradProdCode:tradProdCode,tradProdDesc:tradProdDesc_val,tradAppType:tradAppType_val,prodInstCode:prodInstCode_val,instant:instant_val,maxDelayDay:maxDelayDay_val,maxDays:maxDays_val,minDays:minDays_val,unitPp:unitPp_val,status:status_val,prodType:prodType_val,poolType:poolType_val,poolRatio:poolRatio_val,ageLimit:limit_val,minAge:minage_val,maxAge:maxage_val,maxOccupLevel:maxOccupLevel_val,insuredNoLimit:insuredNoLimit_val,minInsuredNo:minInsuredNo_val,minDelayDay:minDelayDay_val,
				adjustStr:adjustStr_val,agentType:agentType_val,pppUnit:PPP_UNIT_val});
}


function loadtemplet(param){
	$.openLoading();
	$.ajax({
		url : "product/loadTemplet",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
			$.closeLoading();
			if($.validate(page))return;
			
			startP = page.current;
			var firstbutton ="<input class='input_fxk' name='radioTemple' type='radio' value=''>";
			var tableContent = creatTable1("inst_code,prod_nme",page,firstbutton,null);
			var tableObj = $("#productTempletTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			
			var strPage = creatChannelPage(startP,6,page.maxPage,"11");
			var pageDIV = $("#productTempletpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			bindredio();
			$("#addtempletDiv").OpenDiv();
		}
	});
}


function bindredio(){
	$("input[name='radioTemple']").click(function(){
		$("input[name='radioTemple']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}

function saveTradProInst(param){
	
	if(!Formstatus){
		$.message("error", "处理中请勿重复提交");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "product/editProduct",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			$.closeLoading();
			Formstatus=true;
			if($.validate(obj))return;
			if("other"==obj.result){
				$("#status").find("option[value='0']").attr("selected",true);
				$.dialog({
					type: "warn",//success,error
					content: "定义未完成只可为无效状态,是否定义产品险种?",
					onOk: function() {
						openInsurance();
						return;
					}
				});
				return;
			}
			$.dialog({
				type: "success",//success,error
				content: "产品修改成功,是否继续修改险种配置?",
				onOk: function() {
					openInsurance();
					return;
				}
			});
		}
	});
}
function queryProductTemplet(pagenum){
	var prodNme= $("#fprodNme").val();
	var instCode= $("#finstCode").val();
	loadtemplet({current:pagenum,size:10,prodNme:prodNme,instCode:instCode});
}
function chooseTemplet(){
	var radioTemple = $("input[name='radioTemple']:checked");
	var instCode= radioTemple.parent().parent().children(" td:eq(1)").html();
	var prodNme= radioTemple.parent().parent().children(" td:eq(2)").html();
	$("#prodNme").val(prodNme);
	$("#prodInstCode").val(instCode);
	closetempletDiv();
}

function fvreset(){
	$("#fprodNme").val("");
	$("#finstCode").val("");
}
function vreset(){


	$("#unitPp").val("");//最大份数
	$("#maxDelayDay").val("");//最长延时起保天数
	$("#minDelayDay").val("");//最短延时起保天数
	$("#minDays").val("");//保险期间最小
	$("#maxDays").val("");//保险期间最大
	$("#PPP_UNIT").val(0);//保险期间
	$("#tradProdDesc").val("");//交易系统产品描述
	$("#instant").find("option[value='N']").attr("selected",true);//是否即时投保
	$("#status").find("option[value='0']").attr("selected",true);//产品状态
	
	$('#poolType').val(0);//共保选项
	$('#poolRatio').val('');//共保份额
	$("#poolRatio").attr('readOnly',true);
	$("#poolRatio").css('background-color','#ccc');
	
	$("#ageLimit").val(0);//是否限制投保年龄
	$("#maxAge").val('');//最大年龄
	$("#minAge").val('');//最小年龄
	$("#maxAge").attr('readOnly',true);
	$("#minAge").attr('readOnly',true);
	$("#maxAge").css('background-color','#ccc');
	$("#minAge").css('background-color','#ccc');
	
	$("#maxOccupLevel").val(0);//最高职业类别
	$("#insuredNoLimit").val(0);//是否限制最低投保人数
	$("#minInsuredNo").val('');//最低投保人数
	$("#minInsuredNo").attr('readOnly',true);
	$("#minInsuredNo").css('background-color','#ccc');

}
function opentempletDiv(obj){
	$("#"+obj.id).blur();
	loadtemplet("");
}
function closetempletDiv(){
	fvreset();
	$("#addtempletDiv").CloseDiv();
}
function openProductList(){
	window.location.href='<%=basePath%>product/list';
}
function openInsurance(){
	window.location.href='<%=basePath%>product/prodPlan?tradProdCode='+tradProdCode;
}

//当“共保选项”的值为“保单级共保”时，共保份额可输入，且为必填，否则不允许输入共保份额
function checkType(obj){
	var type = $('#'+obj.id).val();
	if(type==1){
		$('#poolRatio').attr("readonly",false);
		$('#poolRatio').css("background-color","white");
	}else{
		$('#poolRatio').val('');
		$('#poolRatio').attr("readonly",true);
		$('#poolRatio').css("background-color","#ccc");
	}
}


//选择是否限制投保年龄下拉框
function checkLimit(){
	var limitFlag = $('#ageLimit').val();
	if(limitFlag=="Y"){
		$('#minAge').attr('readOnly',false);
		$('#minAge').css('background-color','white');
		$('#maxAge').attr('readOnly',false);
		$('#maxAge').css('background-color','white');
	}else{
		$('#minAge').attr('readOnly',true);
		$('#minAge').css('background-color','#ccc');
		$('#maxAge').attr('readOnly',true);
		$('#maxAge').css('background-color','#ccc');
		$('#maxAge').val('');
		$('#minAge').val('');
	}
	
}
//选择是否限制最低投保人数下拉框
function checkInsuredNoLimit(){
	var personFlag = $('#insuredNoLimit').val();
	if(personFlag=="Y"){
		$('#minInsuredNo').attr('readOnly',false);
		$('#minInsuredNo').css('background-color','white');
	}else{
		$('#minInsuredNo').attr('readOnly',true);
		$('#minInsuredNo').css('background-color','#ccc');
		$('#minInsuredNo').val('');
	}
}
/*-----------------2015年6月5日10:44:25-----wangyan------add↓---*/
//校验折扣系数
function chectAdjust(){
	var  flag= true;
	$("#adjustDiv").find("input[type='text']").each(function(){
		if($(this).attr("name")=="peoplenum"){
			if($.trim($(this).val())==""){
				$.message("error","折扣系数:人数不能为空");
    	    	$(this).focus();
    	    	flag= false;
    	    	return false;
    		}else{
    			var regPeopleNum = /^([1-9]\d{0,3}|0)$/;
    			if(!regPeopleNum.test($(this).val())){
	    	    	$.message("error","折扣系数(人数):请输入0-9999的整数");
	    	    	$(this).focus();
	    	    	flag= false;
	    	    	return false;
    			}
    		}
		}else if($(this).attr("name")=="coefficient"){
			if($.trim($(this).val())==""){
    	    	$.message("error","折扣系数:百分比不能为空");
    	    	$(this).focus();
    	    	flag= false;
    	    	return false;
    		}else{
    			var regCoefficient = /^([1-9]\d{0,2}|0)$/;
    			if(!regCoefficient.test($(this).val())){
	    	    	$.message("error","折扣系数(百分比):请输入0-999的整数");
	    	    	$(this).focus();
	    	    	flag= false;
	    	    	return false;
    			}
    		}
		}
    });
	return flag;
}
function changeAdjust(){
	var adjustVal= $("#adjust").val();
	if(adjustVal==""){
		$("#adjustDiv").empty();
		$("#adjustDiv").append("<div>"+
				"<input name='peoplenum' type='text' style='background-color: #ccc;width:55px;' readonly='readonly'  class='input_text'>&nbsp;人&nbsp;<input name='coefficient' type='text'  style='background-color: #ccc;width:55px;' readonly='readonly' class='input_text'>&nbsp;%&nbsp;&nbsp;<input type='button'  id='addSale' value='+' onclick='addAdjustDiv()'>"
	    		+"</div>");
	}else{
		$("#adjustDiv").find("input[type='text']").each(function(){
			$(this).attr('readOnly',false);
			$(this).css('background-color','white');
	    });
	}
}
/*-----------------2015年6月5日10:44:25------wangyan-----add↑-----*/
</script>
</head>
<body>
<div class="right">
	      <div class="current">
	           <table class="current_table_1">
	              <tbody><tr>
	                <td><img src="./images/current_1.jpg"></td>
	                  <td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
	                  <span style=" color:#136bab; ">产品管理
	                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
	                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>编辑产品
	                  </span>
	                  </td>
	                  <td><img src="./images/current_3.jpg"></td>
	              </tr>
	           </tbody>
	          </table>
	      </div>
	      
			<form id="inputForm" >
	        <table class="table_05">
	              <tbody>
	              <tr>
	                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">编辑产品</td>
	              </tr>
	    		  <tr>
	                  <th width="25%">产品模板代码：</th>
	                  <td width="28%">
	                  	<input name="prodInstCode" id="prodInstCode"  value="${product.prodInstCode}" type="text" readonly="true" style="background-color:#ccc;width:250px;" class="input_text"><span class="red">*</span>&nbsp;
	                  	<c:if test="${empty product.tradProdCode}">
	                  		<input type="button"  class="input_button_2" id="searchMBBtn" value="选择模板" onClick="opentempletDiv(this)"/>
	                  	</c:if>
	                  </td>
	                  <th width="22%">产品模板名称：</th>
	                  <td width="20%"><input id="prodNme" value="${product.prodNme}" type="text" readonly="true" style="background-color:#ccc;width:250px;" class="input_text"><span class="red">*</span></td>
	              </tr>

	               <tr>
	                  <th>个团标识：</th>
	                  <td><select name="tradAppType" id="tradAppType" class="select_1" style="visibility: visible;width:250px;"><option value="0">个单</option><option value="1">团单</option></select><span class="red">*</span></td>
	                  <th>界面投保流程：</th>
	                 <td><select name="instant" id="prodType" class="select_1" style="visibility: visible;width:250px;"><option value="0">------------------请选择------------------</option></select><span class="red">*</span></td>
	              </tr>
	               <tr>
	                  <th>最短延时起保天数：</th>
	                  <td><input name="minDelayDay"  id="minDelayDay" value="${product.minDelayDay}" type="text" maxlength="5" class="input_text" style="width:250px;"><span class="red">*</span></td>
	                  <th>最长延时起保天数：</th>
	                  <td><input name="maxDelayDay"  id="maxDelayDay" value="${product.maxDelayDay}" type="text" maxlength="5" class="input_text" style="width:250px;"><span class="red">*</span></td>
	              </tr>
	              <tr>
	                  <th>保险期间：</th>
	                  <td>
	                  	<input name="minDays" id="minDays" maxlength="5" value="${product.minDays}"  type="text" class="input_text" style="width:60px;">&nbsp;至&nbsp;
	                    <input name="maxDays" id="maxDays" maxlength="5" value="${product.maxDays}"  type="text" class="input_text" style="width:60px;">&nbsp;&nbsp;
	                    <select name="PPP_UNIT" id="PPP_UNIT" class="select_1"  style="width:55px;visibility: visible;"></select><span class="red">*</span>
	                  </td>
	                  <th>销售类型：</th>
	                  <td>
		                  <select id="agentType" class="select_1" style="visibility: visible;width:250px;">
		                  	<option value="">--------请选择--------</option>
		                  	<c:forEach var ="agentType" items="${agentTypeList}">
	                  			<option value="${agentType.code}">${agentType.codeName}</option>
	                  		</c:forEach>
		                  </select><span class="red">*</span>	
	                  </td>
	              </tr>
	              <tr>
	                  <th>共保选项：</th>
	                  <td><select id="poolType" onchange="checkType(this)" class="select_1" style="visibility: visible;width:250px;"></select><span class="red">*</span></td>
	                  <th>共保份额：</th>
	                  <td><input id="poolRatio" type="text" readonly="true" style=" background-color: #ccc;width:250px;" class="input_text">&nbsp;<span style="font-size:16px;vertical-align:middle;">%</span><span class="red">*</span></td>
	              </tr>       
	              <tr>
	                  <th>是否支持即时投保：</th>
	                  <td><select name="instant" id="instant" class="select_1" style="visibility: visible;width:250px;"><option value="N">否</option><option value="Y">是</option></select><span class="red">*</span></td>
	                  <th>被保人年龄限制：</th>
	                  <td>
	                  	<select id="ageLimit" onchange="checkLimit()" class="select_1" style="visibility: visible;width:100px;">
	                  		<option value="">----请选择----</option>
	                  		<option value="Y">是</option>
	                  		<option value="N">否</option>
	                  	</select><span class="red">*</span>
	                  <input id="minAge" type="text" value="${product.minAge}" readonly="true" style=" background-color: #ccc;width:55px;" class="input_text">&nbsp;到&nbsp;<input id="maxAge" type="text" value="${product.maxAge}" readonly="true" style=" background-color: #ccc;width:55px;" class="input_text">&nbsp;周岁
	                  </td>
	              </tr>
	              <tr>
	                  <th>最高职业类别：</th>
	                  <td><select name="maxOccupLevel" id="maxOccupLevel" class="select_1" style="visibility: visible;">
	                  		<option value="">不限制</option>
	                  		<option value="1">1类</option>
	                  		<option value="2">2类</option>
	                  		<option value="3">3类</option>
	                  		<option value="4">4类</option>
	                  		<option value="5">5类</option>
	                  		<option value="6">6类</option>
	                  	  </select><span class="red">*</span></td>
	                  <th>最低被保人数限制：</th>
	                  <td>
	                  	<select id="insuredNoLimit" onchange="checkInsuredNoLimit()" class="select_1" style="visibility: visible;width:100px;">
	                  		<option value="">----请选择----</option>
	                  		<option value="Y">是</option>
	                  		<option value="N">否</option>
	                  	</select><span class="red">*</span>
	                  	<input id="minInsuredNo" value="${product.minInsuredNo}"  type="text" readonly="true" style=" background-color: #ccc;width:55px;" class="input_text">&nbsp;人
	                  </td>
	              </tr>
	              <tr>
	                  <th>最大份数：</th>
	                  <td><input name="unitPp"  id="unitPp" value="${product.unitPp}" type="text" maxlength="5" class="input_text"><span class="red">*</span></td>
	                  <th>状态：</th>
	                  <td><select  name="status" id="status" class="select_1" style="visibility: visible;width:250px;"><option  value="0">无效</option><option value="1">有效</option></select><span class="red">*</span></td>
	              </tr>
	              <tr>
	              	  <th>折扣系数：</th>
	                  <td  colspan="3">
	                  	<div id="adjustDivLeft" style="float: left;width:135px;">
	                  		<select id="adjust" onchange="changeAdjust()"  class="select_1" style="visibility: visible;width:100px;"><option value="">无</option></select><span class="red">*</span>&nbsp;&nbsp;
	                  	</div>
	                  	<div id="adjustDiv" style="float: left;">
	                  		<div>
	                  			<input name="peoplenum" type="text" style="width:55px;" class="input_text">&nbsp;人&nbsp;<input name="coefficient" type="text"  style="width:55px;" class="input_text">&nbsp;%&nbsp;&nbsp;<input type="button"  id="addSale" value="+" onclick="addAdjustDiv()">
	                  		</div>
	                  	</div>
	                  </td>
	              </tr>
	              <tr>
	                  <th>交易系统产品描述：</th>
	                  <td colspan="3"><textarea name="tradProdDesc" id="tradProdDesc" maxlength="50" rows="5" class="textarea_1">${product.tradProdDesc}</textarea><span class="red">*</span></td>
	              </tr>
	           </tbody>
	           </table> 
	           <div align="center">
	              <input class="input_button_1" name="" type="button" value="确定" onclick="addProduct()">&nbsp;&nbsp;
	              <input class="input_button_1" name="" type="button" onclick="vreset()"  value="重置">
	           </div>
	           </form>
	      </div>
	</div>      
</div>

		<!--   	添加模板 DIV 默认隐藏-->
  		<div id="addtempletDiv"  style="display:none;width:80%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closetempletDiv()"/></td>
						</tr>
					
					</table>
			</div>
		<form id="inputForm" action="save.jhtml" method="post" enctype="multipart/form-data">
			
			<table class="table_02" id="addtempletTable" style="height:180px;" align="center" >
				<tbody>
					<tr>
						<td>
							<table class="search_table">
								<tbody>
									<tr height="30px">
										<td width="20%" height="30"></td>
										<td width="30%" height="30">产品模板代码：
											<input name="txt3" id="finstCode" type="text" class="input_text" value="">
										</td>
										<td width="30%" height="30">产品模板名称：
											<input name="txt3" id="fprodNme" type="text" class="input_text" value="">
										</td>
										<td width="20%" height="30">
										   <input type="button" class="input_button_1" id="searchBtn" value="查询" onclick="queryProductTemplet(1)">&nbsp;
										   <input type="button" class="input_button_1" id="searchBtn" value="重置" onclick="fvreset()">
										</td>
									</tr>	
								</tbody>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table id="productTempletTable"  class="content_table_1">
								<thead>
									<tr class="f1">
					                  <th style="width:5%">选择</th>
					                  <th style="width:45%">产品模板代码</th>
					                  <th style="width:40%">产品模板名称</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="productTempletpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			 <input class="input_button_3" name="" type="button" onclick="chooseTemplet()" value="确定">&nbsp;&nbsp;
	         <input class="input_button_3" name="" type="button" onclick="closetempletDiv()" value="取消">
			</div>
		</form>
	</div>
</body>
</html>